package com.example.archive.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.archive.entity.Notice;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface NoticeMapper extends BaseMapper<Notice> {
    
    @Select("SELECT n.*, COALESCE(u.name, u.username) as publisher_name FROM notices n " +
            "LEFT JOIN users u ON n.publisher_id = u.user_id " +
            "WHERE n.status = 'published' ORDER BY n.publish_time DESC")
    List<Notice> selectPublishedNotices();
    
    @Select("SELECT n.*, COALESCE(u.name, u.username) as publisher_name FROM notices n " +
            "LEFT JOIN users u ON n.publisher_id = u.user_id " +
            "ORDER BY n.publish_time DESC")
    Page<Notice> selectNoticesWithPublisher(Page<Notice> page);
} 